package com.sky.controller.user;

import com.sky.entity.Setmeal;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.DishItemVO;
import com.sky.vo.SetmealVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController("userSetmealController")
@Api(tags = "C端")
@RequestMapping("/user/setmeal")
@Slf4j
public class SetmealController {

    @Resource
    private SetmealService setmealService;
    /*
    * 通过分类id查询套餐
    * */
    @GetMapping("/list")
    @ApiOperation("通过分类id查询套餐")
    @Cacheable(cacheNames = "setmealCache",key = "#categoryId")
    public Result<List<Setmeal>> list(@RequestParam Long categoryId){
        log.info("通过分类id查询套餐:{}",categoryId);
        List<Setmeal> setmealList = setmealService.queryByCategoryId(categoryId);
        return Result.success(setmealList);
    }

    /*
    * 根据套餐id查询菜品列表
    * */
    @ApiOperation("根据套餐id查询菜品列表")
    @GetMapping("/dish/{id}")
    public Result listDish(@PathVariable Long id){
        log.info("根据套餐id查询菜品列表:{}",id);
        List<DishItemVO> dishItemVOS = setmealService.queryItemById(id);
        return Result.success(dishItemVOS);
    }

}
